package main

import (
	"flag"
	"fmt"
	"zhoubao/lib"
	_ "zhoubao/routers"

	"gitee.com/konyshe/gogo"
)

var (
	sqlIsInitedgo = false
)

func SQLInit() {
	if !sqlIsInitedgo {
		gogo.CheckErrorExit(gogo.SQLInit("mysql", lib.GetConfigData().DATA_SOURCE, 500, 3))
	}
}

func main() {
	printMainVersion := false
	flag.BoolVar(&printMainVersion, "version", printMainVersion, gogo.BuildTime())

	flag.Parse()

	if printMainVersion { //只列出版本号就结束
		fmt.Println(gogo.BuildTime())
		return
	}

	gogo.LogInit(lib.GetConfigData().LOG_LEVEL, lib.GetConfigData().LOG_MAX_SIZE)

	SQLInit()

	go gogo.StartWebSocket("/ws", lib.GetConfigData().SERVER_PORT+1, webSocketHandle)

	gogo.StartHTTP(lib.GetConfigData().SERVER_PORT)
}
